import sys, os, subprocess

php_config = '/usr/bin/php-config'
#php_config = '/www/zhaowei/php/bin/php-config'

x = subprocess.Popen(php_config + ' --includes', stdout=subprocess.PIPE, shell=True)
php_includes = x.stdout.read().strip().split()

os.system('swig -php -o memlink_client_php.c ../c/memlink_client.i')

cflags   = '-ggdb -O2'
includes = ['.', '../../', '../c/', '/Developer/usr/include'] + php_includes
libpath  = ['.']
libs	 = ['m']
files    = ['../../zzmalloc.c', '../../serial.c', '../../logfile.c', '../../utils.c', 
			'../c/memlink_client.c']

env = Environment(CCFLAGS=cflags, CPPPATH=includes, LIBPATH=libpath, LIBS=libs)
shared_files = []
for fn in files:
    name = os.path.basename(fn)[:-2]
    shared_files.append(env.SharedObject('client-' + name, fn))
shared_files.append('memlink_client_php.c')

env.SharedLibrary("memlink", shared_files)

Command('memlink.so', 'libmemlink.so', [Move('$TARGET', '$SOURCE'), Copy('memlink.php', 'memlink_php.php')])
